package studychinese.adapters;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.hschinese.pronunciation.R;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;


/**
 * Created by lenovo on 2017/4/9.
 */
public class NativeCountryAdapter extends AppAdapter {
    private int mPosstion=-1;

    public NativeCountryAdapter(List list, Context context) {
        super(list, context);

    }
  /*  */








    @Override
    public View createView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.fragment_native_city_icon, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

       // GlideUtil.loadImgUrl(context,list.get(position).toString(),viewHolder.ivNativeCityIcon);
        Glide.with(context).load(list.get(position))
                .diskCacheStrategy(DiskCacheStrategy.NONE)
                  .into(viewHolder.ivNativeCityIcon)
            ;
        if(mPosstion==position){
            viewHolder.iv_native_city_icon_down.setVisibility(View.VISIBLE);
        }else {
            viewHolder.iv_native_city_icon_down.setVisibility(View.INVISIBLE);
        }

        return convertView;
    }


    static class ViewHolder {
        @Bind(R.id.iv_native_city_icon)
        ImageView ivNativeCityIcon;
        @Bind(R.id.iv_native_city_icon_down)
        ImageView iv_native_city_icon_down;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
    public void update(int position, GridView mListView){
           /* int visiblePosition = mListView.getFirstVisiblePosition();
            View view = mListView.getChildAt(position - visiblePosition);
            ImageView txt = (ImageView) view.findViewById(R.id.iv_native_city_icon_down);
            txt.setVisibility(View.VISIBLE);*/
           mPosstion=position;
    }
}
